#-----------------------------------------------------------------------------
# Project:     Multi-Programmer Game Demo
# Name:        Paddle.py
# Purpose:     Controllable Paddle Object
# 
# Authors:     Chris Spooner, Chris La-Roo
# Main Author: Chris Spooner
#
# Created:     11/30/2012
# Copyright:   (c) Chris Spooner 2012
# Licence:     New BSD
#-----------------------------------------------------------------------------
import pygame, math

class Paddle():
    def __init__(self, images, speed, screenSize, waitMax = 1000):
        self.surfaces = []
        for image in images:
            self.surfaces += [pygame.image.load(image)]
        self.frame = 0
        self.waitCount = 0
        self.waitMax = waitMax
        self.maxFrame = len(self.surfaces)-1
        self.surface = self.surfaces[self.frame]
        self.rect = self.surface.get_rect()
        self.radius = self.rect.width/2
        self.speed = speed
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.shootDir = ""
    
    def move(self):
        self.rect = self.rect.move(self.speed)
        if self.waitCount < self.waitMax:
            self.waitCount += 1
        else:
            self.waitCount = 0
        
            if self.frame < self.maxFrame:
                self.frame += 1
            else: 
                self.frame = 0
            self.surface = self.surfaces[self.frame]
    def place(self, pt):
        self.rect = self.rect.move(pt)
        
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))

    
     
    def wallCollide(self):
        if (self.rect.left < 0 
            or self.rect.right > self.screenWidth):
            self.speed[0] = self.speed[0] = 0
        if (self.rect.top < 0 
            or self.rect.bottom >self.screenHeight):
            self.speed[1] = self.speed[1] = 0
    
    def borderCollide(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom): 
                    self.speed[0] = self.speed[0] = 0
     
                    
    